<?php
/**
 * 我的主页
 */
require_once dirname(__DIR__)."/login_filter.php";
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\model\Users;

$uuid=$Auth['uuid'];
$uid=sprintf("%d",crc32($uuid));
$key1=REDIS_PREFIX."fabulous_".$uid;//点赞
$key2=REDIS_PREFIX."follow_".$uid;//关注
$key3=REDIS_PREFIX."is_follow_".$uid;//被关注（粉丝）
//实例化redis
$redis = SysResource::getRedis();
//实例化数据库
$db = SysResource::getDB(false);
$Users = new Users($db);
//1.从redis里获取我的关注量
//$da1=$redis->hKeys($key2);
$da1="";
if(!empty($da1)){
    //redis里不为空
    $da1_len=count($da1);
}else{
    $da1=$Users->follow($uuid);
    $da1_len=count($da1);
}
//2.从redis里获取我的粉丝（我被别人关注的）
//$da2=$redis->hKeys($key3);
$da2="";
if(empty($da2)){
    //再从数据库获取我的粉丝
    $da2=$Users->is_follow($uuid);
}
$da2_len=count($da2);

//3.获取我的作品个数
$count_material=$Users->count_material($uuid);
//4.
//先去redis里查我的点赞
//$count_love=$redis->hKeys($key1);
$count_love="";
if(empty($count_love)){
    //为空再去数据库查
    $count_love=$Users->count_love($uuid);
    $count_love=array_filter($count_love);
}
//5.去数据库查询用户的所有赞
$count_zan=$Users->count_zan123($uuid);
//if(empty($count_zan['total'])){
//    $count_zans=0;
//}else{
//    $count_zans=$count_zan['total'];
//}
$zan1="";
$zan2="";
foreach($count_zan as $k=>$v){
    if($v['count_material_love']>0){
        $zan1+=$v['count_material_love'];
        $zan2+=round($v['count_material_love']*1.7);
    }
}

//再去查询自己的用户信息
$my_home=$Users->my_home($uuid);
$my_home['follow']=$da1_len;
$my_home['is_follow']=$da2_len;
$my_home['count_material']=$count_material;
$my_home['count_love']=count($count_love);
$my_home['count_zan']=$zan1;
$my_home['count_zan_10']=$zan2;
if(empty($my_home['user_autograph'])){
    $my_home['user_autograph']="";
}
//再去查询
Response::output(0,"查询成功",$my_home);





